package com.example.demo.controller;

import com.example.demo.domain.Question;
import com.example.demo.service.QuestionService;
import com.example.demo.service.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @GetMapping("/question/{id}")
    public Response<Question> getQuestionById(@PathVariable long id)
    {
        return Response.newSuccess(questionService.getQuestionById(id));
    }

    @GetMapping("/question/list")
    public Response<List<Question>> getQuestionList()
    {
        return Response.newSuccess(questionService.getQuestionList());
    }

    @PostMapping("/question/add")
    public Response<Long> addNewQuestion(@RequestBody Question question) {
        return Response.newSuccess(questionService.addNewQuestion(question));
    }

}
